package com.cdyx.yygh.cmn.controller;



import com.alibaba.excel.EasyExcel;
import com.cdyx.common.result.Result;
import com.cdyx.model.cmn.Dict;
import com.cdyx.yygh.cmn.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.http.HttpResponse;
import java.util.List;

@Api("数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin//这个注解允许跨域访问
public class CmnController {
  @Autowired
    private DictService dictService;
  @ApiOperation(value = "根据id查询数据字典列表")
  @GetMapping("findChildData/{id}")
  public Result findChildData(@PathVariable Long id){
    List<Dict> dictList=dictService.findChildData(id);
    return Result.ok(dictList);
  }
  //导出数据
  @ApiOperation(value="EXCEL表格导出数据")
  @GetMapping("downloadExcel")
  public void downloadExcel(HttpServletResponse response){
    dictService.downloadExcel(response);
  }
  @CrossOrigin//这个注解允许跨域访问
  @ApiOperation(value = "EXCEL表格读取数据到数据库")
  @PostMapping("importData")
  public Result importData(MultipartFile file){
    dictService.importData(file);
    return Result.ok();
  }
}
